//
//  AppDelegate.m
//  百思不得姐
//
//  Created by 郝庆 on 16/6/1.
//  Copyright © 2016年 haoqing. All rights reserved.
//

#import "AppDelegate.h"
#import "LZTabBarController.h"
#import "LZTopWindow.h"

@interface AppDelegate ()<UITabBarControllerDelegate>
/** 记录上一次选中的子控制器的索引 */
@property (nonatomic, assign) NSUInteger lastSelectedIndex;
@end

@implementation AppDelegate

#pragma mark - <UITabBarControllerDelegate>
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if (tabBarController.selectedIndex == self.lastSelectedIndex) { // 重复点击了同一个TabBar按钮
        // 发出通知
        [[NSNotificationCenter defaultCenter] postNotificationName:LZTabBarButtonDidRepeatClickNotification object:nil];
    }
    
    // 记录目前选中的索引
    self.lastSelectedIndex = tabBarController.selectedIndex;
}

#pragma mark - <UIApplicationDelegate>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    LZTabBarController *tabBarVc = [[LZTabBarController alloc] init];
    self.window.rootViewController = tabBarVc;
    tabBarVc.delegate = self;
    [self.window makeKeyAndVisible];
    
    // 添加一个最高级别的顶层window
    [LZTopWindow show];
    return YES;
}


@end
